<template>
  <tbody>
    <tr v-for="(item, index) in arr" :key="index">
      <td><input v-model="item.checked" type="checkbox"></td>
      <td> {{ item.name }} </td>
      <td> {{ item.price }} </td>
      <td>
        <button @click="btnSub(index)">-</button>
        {{ item.num }}
        <button @click="btnAdd(index)">+</button>
      </td>
      <td> {{ item.price*item.num }} </td>
      <td><button @click="del(index)">删除</button></td>
    </tr>
  </tbody>
</template>

<script>
export default {
  props:['arr'],
  methods: {
    btnSub(index){
      if(this.arr[index].num<=0) return alert('数量不能小于0')
      this.arr[index].num--
    },
    btnAdd(index){
      this.arr[index].num++
    },
    del(index){
      this.$emit('delInd',index)
    }
  }
}
</script>

<style scoped>
</style>
